package com.rongxun.base;

import android.support.annotation.NonNull;

/**
 * 创建者     庄丰泽
 * 创建时间   2018/5/18 13:23
 * 描述	      mvp基类
 */

public abstract class MvpActivity<V extends IBase.IView,P extends IBase.IPresenter> extends BaseActivity implements MvpCallBack<V,P>{

    private P presenter;

    @NonNull
    @Override
    public P getPresenter() {
        if (presenter == null) {
            presenter = createPresenter();
        }
        return presenter;
    }


    @Override
    public void setPresenter(@NonNull P presenter) {
        this.presenter = presenter;
    }

    @NonNull
    @Override
    public V getMvpView() {
        return (V) this;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (presenter != null){
            presenter.release();
        }
    }
}
